﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AMS.Inventory.PDA.Core.DataAccess; 
using AMS.Inventory.PDA.Castle.DataAccess;
using System.Collections;

namespace AMS.Inventory.PDA
{
    public partial class FrmMain : Form
    {

        public FrmMain()
        {
            InitializeComponent();
            hashTable=clsLocalization.ReadContectResource(this.Name, "");
        }

        private SqliteDBServer _sqldb = null;
        private string _userName = null;   
        private Hashtable hashTable;
        private  bool _islogin;
        private void FrmMain_Load(object sender, EventArgs e)
        {
            clsLocalization.getControlNames(this); 
            FrmLogin frmLogin =new FrmLogin();
             frmLogin.ShowDialog();
            _islogin = frmLogin.IsLongin;
            if(_islogin)
            {
               _userName = frmLogin.UserName;
               _sqldb = frmLogin.SqlDb;
            }
            else
            {
                Close();
                return;
            }

        }

        private void FrmMain_Closing(object sender, CancelEventArgs e)
        {
            if (_islogin)
            {
             if (DialogResult.Yes ==
                MessageBox.Show(clsLocalization.getFromContentNames(hashTable, "IsExistSys"),ModCommon.MagboxTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                MessageBoxDefaultButton.Button1))
            {
                if (this._sqldb != null && this._sqldb.SqliteConnect != null)
                {
                    _sqldb.SqliteConnect.Close();
                }
            }
            else
            {
                e.Cancel = true;
            }
            
        }

    }

        private void BtnChecking_Click(object sender, EventArgs e)
        {
            if (this._sqldb.SqliteConnect == null)
            {
                this._sqldb.ConnectedDbOpen();
                this.BtnCloseConn.Text = clsLocalization.getFromContentNames(hashTable, "ConnClose");
                this.LblConnMessagae.Text = clsLocalization.getFromContentNames(hashTable, "ConnOpenMsg"); 
            }
            else
            {
                this._sqldb.ConnectedDbClose();
                this.BtnCloseConn.Text = clsLocalization.getFromContentNames(hashTable, "ConnOpen");
                this.LblConnMessagae.Text = clsLocalization.getFromContentNames(hashTable, "ConnCloseMsg");
                    }
            FrmPlanInfoList frmCheckInfoList=new FrmPlanInfoList(this._userName,this._sqldb);
            frmCheckInfoList.ShowDialog();
        }

        private void BtnCloseConn_Click(object sender, EventArgs e)
        {
            if(this._sqldb.SqliteConnect==null )
            {
                this._sqldb.ConnectedDbOpen();
                this.BtnCloseConn.Text = clsLocalization.getFromContentNames(hashTable, "ConnClose");
                this.LblConnMessagae.Text = clsLocalization.getFromContentNames(hashTable, "ConnOpenMsg");
            }
            else
            {
                this._sqldb.ConnectedDbClose();
                this.BtnCloseConn.Text = clsLocalization.getFromContentNames(hashTable, "ConnOpen");
                this.LblConnMessagae.Text = clsLocalization.getFromContentNames(hashTable, "ConnCloseMsg");
            }
        }

        private void FrmMain_Closed(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}